<?php
namespace Admin\Controller;
use Think\Controller;

class CategoryController extends CommonController {
	 private $_model;
	 function _initialize(){
            $this->_model=D('Category');
        }
	//显示分类首页
	public function index() {
		$data=$this->_model->get_data();
		$this->assign('data',$data);
		$this->display();

	}
	//添加顶级分类

	public function add() {
		if(IS_POST){
			$data=$_POST;
			$this->_model->add_data($data);
			$this->error("添加成功",U('Category/index'));
		}
		$this -> display();
	}

	//修改
	public function edit_cate(){
		if(IS_POST){
			$cid=I('post.id');
			$where=array('cid'=>$cid);
			$data=$_POST;
			$this->_model->save_data($where,$data);
			$this->error("修改成功",U('Category/edit_cate',array('cid'=>$cid)));
		}
		$cid=I('get.cid',0,'intval');
		$where=array('cid'=>$cid);
		$data=$this->_model->get_data($where);

		$this->assign('data',$data);
		$this->display();
	}

	//删除
	public function del(){
		$cid=I('get.cid',0,'intval');
		$where=array('cid'=>$cid);
		$this->_model->del_data($where);
		$this->error("删除成功",U('Category/index'));
	}
}
?>